﻿@extends('layouts.shop_main')

@section('title', '地推订单')

@section('resources')
    @parent
    <style>
        .header{margin: 0 30px 20px 30px;padding: 10px 0;overflow: hidden;border-bottom: 1px solid #eee;}
        .header p{float: left;font-size: 18px;}
        .header a{float: right;padding: 4px 20px;border: 1px solid #9955c6;border-radius: 3px;color: #9955c6;}
        .search{margin: 0 30px;}
        .search li{overflow: hidden;margin: 20px 0;}
        .search li p{float: left;overflow: hidden;}
        .search li p span{float: left;width: 100px;text-align: right;font-size: 14px;color: #808080;line-height: 25px;padding-right: 10px;}
        .search li p input{float: left;width: 200px;height: 25px;border: 1px solid #eee;border-radius: 3px;padding: 5px;}
        .search li p select{float: left;width: 200px;height: 25px;border: 1px solid #eee;border-radius: 3px;}
        .search li table td{text-align: center;font-size: 14px;padding: 10px 0;color: #808080;}
        .search li table{border-top: 1px solid #DEE3EA;border-bottom: 1px solid #DEE3EA;}
        .search li table tbody tr:nth-child(2n+1){background-color: #F3F3F3;}
        .search li table th{text-align: center;font-size: 16px;padding: 10px 0;}
        #last_page{background-color: #9955c6;float: left;width: 100px;height: 35px;color: #fff;display: none;}
        #next_page{background-color: #9955c6;float: right;width: 100px;height: 35px;color: #fff;display: none;}
        .refresh{float: right;width: 90px;background: url({{env('IMAGE_DOMAIN')}}images/shop/bgs/refresh.png) 5px 3px no-repeat;text-align: center;font-size: 16px;color: #9955c6;}
        .salesman_consume{float: left;}
    </style>
@endsection

@section('content')
	<div class="content">
        <div class="header">
            <p>地推订单</p>
        </div>
        <ul class="search">
            <li>
                <p>
                    <span>地推来源：</span>
                    <select name="shopuserid" id="shopuserid">
                    @foreach($shopuserlists as $list)
                        <option value="{{$list['shopuserid']}}">{{$list['shopusername']}}</option>
                    @endforeach
                    </select>
                </p>
                <p>
                    <span>订单时间：</span>
                    <input type="date" name="starttime" value="">
                    <span style="width: 40px;text-align: center;">-</span>
                    <input type="date" name="lasttime" value="">
                </p>
            </li>
            <li>
                <p hidden="hidden">
                    <span>结款状态：</span>
                    <select name="status" id="status">
                        <option value="%">全部</option>
                        <option value="1">已提现</option>
                        <option value="0">未提现</option>
                    </select>
                </p>
                <p style="float: right;">
                    <input style="width: 100px;background-color: #9955c6;color: #fff;height: 30px;" type="button" name="search_all" value="搜索">
                </p>
            </li>
            {{--<li>合计：15笔地推订单 地推订单实付519.90</li>--}}
            <li>
                <span class="salesman_consume"></span>
                <a class="refresh" href="">刷新</a>
            </li>
            <li>
                <table style="width: 100%;" cellpadding="10">
                    <thead>
                        <tr>
                            <th>订单时间</th>
                            <th>用户手机号</th>
                            <th>地推订单实付</th>
                            {{--<th>结款状态</th>--}}
                            <th>地推门店</th>
                            <th>地推来源</th>
                        </tr>
                    </thead>
                    <tbody id="salesman_tbody">
                    
                    </tbody>
                </table>
                <div style="margin-top: 20px;overflow: hidden;">
                    <input id="last_page" type="button" name="" value="上一页">
                    <input id="next_page" type="button" name="" value="下一页">
                </div>
            </li>
        </ul>   
    </div>
@endsection

@section('scriptResources')
    @parent
    <script>
        var starttime = $("input[name='starttime']").val();
        var lasttime = $("input[name='lasttime']").val();
        var shopuserid = $("#shopuserid").val();
        var status = $("#status").val();
        var page = 1;
        var paginate = 10;
        function salesman(page,starttime,lasttime,shopuserid,status){
            $.ajax({
                url : "/shop/salesman/salesman/order/list",
                type : "get",
                data :{
                    starttime:starttime,
                    lasttime:lasttime,
                    shopuserid:shopuserid,
                    status:status,
                    page:page,
                    paginate:paginate
                },
                dataType : "json",
                success:function(data){
                    if(data.status == "success"){
                        $("#salesman_tbody").empty();
                        var data = data.data;
                        var lists = data.lists;
                        $(".salesman_consume").html('合计：'+data.total+'笔地推订单; 地推订单实付' + data.sum);// 地推订单实付519.90
                        if(data.total <= page*paginate){
                            $("#next_page").hide();
                        }else{
                            $("#next_page").show();
                        }
                        if(page <=1){
                            $("#last_page").hide();
                        }else{
                            $("#last_page").show();
                        }
                        for (var i = 0; i < lists.data.length; i++) {
                            var tr = $('<tr>'+
                                        '<td>'+lists.data[i].created_at+'</td>'+
                                        '<td>'+lists.data[i].mobile+'</td>'+
                                        '<td>'+lists.data[i].orderamount+'</td>'+
                                        '<td>'+lists.data[i].shopname+'</td>'+
                                        '<td>'+lists.data[i].shopusername+'</td>'+
                                        '</tr>');
                            $('#salesman_tbody').append(tr);
                        };
                    }else{
                        alert(data.message)
                    }
                }
            });
        }
        salesman(page,starttime,lasttime,shopuserid,status);
        $("input[name='search_all']").click(function(){
            starttime = $("input[name='starttime']").val();
            lasttime = $("input[name='lasttime']").val();
            shopuserid = $("#shopuserid").val();
            status = $("#status").val();
            if(starttime == 0){
                starttime = "2016-07-01";
            }
            if(lasttime == 0){
                var now_date = new Date();
                var year = now_date.getFullYear();
                var month = now_date.getMonth()+1;
                var date = now_date.getDate();
                lasttime = year + "-" + month + "-" + date;
            }
            page = 1;
            salesman(page,starttime,lasttime,shopuserid,status)
        })
        //下一页
        $("#next_page").click(function(){
            page++;
            salesman(page,starttime,lasttime,shopuserid,status);
        })
        //上一页
        $("#last_page").click(function(){
            page--;
            salesman(page,starttime,lasttime,shopuserid,status);
        })
    </script>
@endsection